package com.gosophia.conferenceManagement.starting.ws.test.integration;

import junit.framework.Assert;

import org.hibernate.SessionFactory;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

import com.gosophia.commons.DateTranslate;
import com.gosophia.commons.exception.BusinessException;
import com.gosophia.conferenceManagement.starting.dto.ConferenceStartingDTO;
import com.gosophia.conferenceManagement.starting.entity.ConferenceStartingTransientStore;
import com.gosophia.conferenceManagement.starting.ws.ConferenceTransientStoreWebService;

@ContextConfiguration(locations = { "classpath*:moduleContext.xml",
		"classpath:applicationContext-test.xml" })
public class ITConferenceTransientStoreWebServiceImpl extends
		AbstractTransactionalJUnit4SpringContextTests {

	@Autowired
	private ConferenceTransientStoreWebService conferenceTransientStoreWebService;

	@Autowired
	private SessionFactory sf;

	/**
	 * 测试根据操作人查暂存的方法
	 * 
	 * @throws BusinessException
	 */
	@Test
	public void testFindTransientInfoByCreator() throws BusinessException {
		ConferenceStartingDTO test = conferenceTransientStoreWebService
				.findTransientInfoByCreator(1016L);

		Assert.assertEquals("从业务进入发起申请的测试", test.getConferenceName());
	}

	@Test
	public void testFindTransientInfoByJobId() throws BusinessException {
		ConferenceStartingDTO test = conferenceTransientStoreWebService
				.findTransientInfoByJobId(1L);

		Assert.assertEquals("从任务进入发起会议任务测试", test.getConferenceName());
	}

	@Test
	public void testFindTransientInfoById() throws BusinessException {
		ConferenceStartingDTO test = conferenceTransientStoreWebService
				.findTransientInfoById(2L);

		Assert.assertEquals("从任务进入发起会议任务测试", test.getConferenceName());
	}

	@Test
	public void testSaveTransientInfo() throws BusinessException {
		ConferenceStartingDTO cDTO = new ConferenceStartingDTO();
		cDTO.setApplicationExplanation("applicationExplanation");
		cDTO.setApplicationInfo("applicationInfo");
		cDTO.setConferenceCreatorId(10L);
		cDTO.setConferenceDescription("conferenceDescription");
		cDTO.setConferenceModel("applicationModel");
		cDTO.setConferenceName("conferenceName");
		cDTO.setConferenceType("middleTypeConference");
		cDTO.setConfernceUnderTakerId(1013L);
		cDTO.setHandleAction("handleAction");
		cDTO.setImportentLevel(1012L);
		cDTO.setMajorIssue("majorIssue");
		cDTO.setMajorParticipators("majorParticipators");
		cDTO.setNextHandlerId(1010L);
		cDTO.setPlanEndTime(DateTranslate.simpleStringToDate("2012-01-04"));
		cDTO.setPlanStartTime("大约时间就行");

		ConferenceStartingDTO backDTO = conferenceTransientStoreWebService
				.saveTransientInfo(cDTO);

		Assert.assertEquals("conferenceName", backDTO.getConferenceName());
	}

	@Test
	public void testUpdateTransientInfo() throws BusinessException {
		ConferenceStartingDTO cDTO = new ConferenceStartingDTO();
		cDTO.setConferenceStartingDTOId(1L);
		cDTO.setApplicationExplanation("更新操作后的名字");

		ConferenceStartingDTO backDTO = conferenceTransientStoreWebService
				.updateTransientInfo(cDTO);
		Assert.assertEquals("更新操作后的名字", backDTO.getApplicationExplanation());
	}

	@Test
	public void testDeleteTransientInfoById() throws BusinessException {
		conferenceTransientStoreWebService.deleteTransientInfoById(1L);
		ConferenceStartingTransientStore test = (ConferenceStartingTransientStore) sf
				.getCurrentSession().get(
						ConferenceStartingTransientStore.class, 1L);

		Assert.assertEquals(null, test);
	}
}
